/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgShop
    {
        private readonly Dictionary<int, CfgShop> _dataMap;
        private readonly List<CfgShop> _dataList;


        public TbCfgShop(ByteBuf _buf)
        {
            //first read common data
            _TbCommonShop _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonShop(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgShop>(size * 3 / 2);
            _dataList = new List<CfgShop>(size);

            for (int i = 0; i < size; i++)
            {
                CfgShop _v;
                _v = CfgShop.DeserializeCfgShop(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgShop> DataMap => _dataMap;
        public IReadOnlyList<CfgShop> DataList => _dataList;

        public CfgShop Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgShop] config not found,id:" + key.ToString());

            return null;
        }

        public CfgShop GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "shop";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgShop LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgShop(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgShop
    {
        private CfgShop(ByteBuf _buf, _TbCommonShop _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            EngName = TableCenter.GetI18NText(_buf.ReadInt());
            FunctionOpen = _buf.ReadInt();
            Type = _buf.ReadInt();
            ShowType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ShowCost = _commonData._field0[dataIndex]; }
            npcGroupId = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; RefreshTime = _commonData._field1[dataIndex]; }
            FreeRefreshNumber = _buf.ReadInt();
            ItemRefreshNumber = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; ItemRefreshCost = _commonData._field2[dataIndex]; }
            PayRefreshNumber = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; PayRefreshCost = _commonData._field3[dataIndex]; }
            Timelast = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; GoodsLibraryId = _commonData._field4[dataIndex]; }

            PostInit();
        }

        internal static CfgShop DeserializeCfgShop(ByteBuf _buf, _TbCommonShop _commonData)
        {
            return new CfgShop(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 商店名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 商店英文名称
        /// </summary>
        public string EngName { get; private set; }
        /// <summary>
        /// 功能开启需求
        /// </summary>
        public int FunctionOpen { get; private set; }
        /// <summary>
        /// 商店类型（1、恶域蚀入商店）
        /// </summary>
        public int Type { get; private set; }
        /// <summary>
        /// 显示类型（1-普通商品|2-蕴灵）
        /// </summary>
        public int ShowType { get; private set; }
        /// <summary>
        /// 显示消耗的资源类型
        /// </summary>
        public IReadOnlyList<int> ShowCost { get; private set; }
        /// <summary>
        /// NPC行为ID
        /// </summary>
        public int npcGroupId { get; private set; }
        /// <summary>
        /// 刷新时间
        /// </summary>
        public IReadOnlyList<int> RefreshTime { get; private set; }
        /// <summary>
        /// 免费刷新次数
        /// </summary>
        public int FreeRefreshNumber { get; private set; }
        /// <summary>
        /// 道具刷新次数
        /// </summary>
        public int ItemRefreshNumber { get; private set; }
        /// <summary>
        /// 消耗道具id|数量
        /// </summary>
        public IReadOnlyList<int> ItemRefreshCost { get; private set; }
        /// <summary>
        /// 付费刷新次数
        /// </summary>
        public int PayRefreshNumber { get; private set; }
        /// <summary>
        /// 消耗货币id|数量
        /// </summary>
        public IReadOnlyList<int> PayRefreshCost { get; private set; }
        /// <summary>
        /// 商店持续时间（分）
        /// </summary>
        public int Timelast { get; private set; }
        /// <summary>
        /// 商品库组id|出售栏位
        /// </summary>
        public IReadOnlyList<int> GoodsLibraryId { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonShop
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal _TbCommonShop(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
